import { Controller, Get, Post, Delete, Param, Body } from '@nestjs/common';
import { BookshelfService } from './bookshelf.service';
import { Bookshelf } from './bookshelf.entity';

@Controller('bookshelves')
export class BookshelfController {
  constructor(private readonly bookshelfService: BookshelfService) { }

  @Post()
  async addBook(@Body() data: Partial<Bookshelf>): Promise<Bookshelf> {
    return this.bookshelfService.addBook(data);
  }

  @Get('user/:userId')
  async getBooks(@Param('userId') userId: string): Promise<Bookshelf[]> {
    return this.bookshelfService.getBooksByUser(userId);
  }

  @Delete(':id')
  async removeBook(@Param('id') id: number): Promise<void> {
    await this.bookshelfService.removeBook(Number(id));
  }
}